const files = import.meta.glob('./*.ts', { eager: true });
const modules: any[] = [];
Reflect.ownKeys(files).forEach((key) => {
  if (key === './index.ts') {
    return;
  }
  const mk = (key as string).replace(/(^\.\/|\.ts$)/g, '');
  const mkArr = mk.split('/');
  const m = files[key as string] as any;
  const setFile = (json: any, arr: any, file: any) => {
    if (arr.length > 1) {
      setFile(json, arr.slice(1, arr.length), file);
    } else if (file && file.state) json[mk] = file;
  };
  const file = Object.keys(m).reduce((s, e) => {
    if (e !== 'default') {
      s[e] = m[e];
    }
    return s;
  }, m.default || {});
  setFile(modules, mkArr, file);
});
export default modules;
